package club.zhilin.guli.service.statistics.controller.backend;


import club.zhilin.guli.common.base.result.CommonResult;
import club.zhilin.guli.service.statistics.service.IDailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author zhilin
 * @since 2022-03-05 23:19:33
 */
@Api(tags = "统计分析管理")
@RestController
@RequestMapping("/admin/statistics/daily")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DailyController {

    private final IDailyService iDailyService;

    @ApiOperation("生成统计记录")
    @PostMapping("/create/{date}")
    public CommonResult<String> createStatistics(@PathVariable String date) {
        iDailyService.createStatisticsByDate(date);
        return CommonResult.success("统计数据生成成功");
    }

    @ApiOperation("显示统计数据")
    @GetMapping("/showCharts/{beginTime}/{endTime}")
    public CommonResult<Map<String, Map<String, Object>>> showCharts(@PathVariable String beginTime, @PathVariable String endTime) {
        Map<String, Map<String, Object>> map = iDailyService.selectCharts(beginTime, endTime);
        return CommonResult.success(map);
    }
}

